package com.qf.lanzhou.blog.api.controller.comment;

import com.qf.lanzhou.blog.api.controller.BaseServletPost;
import com.qf.lanzhou.blog.api.pojo.entity.Comment;
import com.qf.lanzhou.blog.api.pojo.entity.User;
import com.qf.lanzhou.blog.api.pojo.vo.CommentVo;
import com.qf.lanzhou.blog.api.service.CommentService;
import com.qf.lanzhou.blog.api.service.impl.CommentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author 是柠檬甜
 * @ClassName CommentShowInListServlet
 * @description 列表页评论展示功能
 * @date 2020/12/17 15:35
 * @modifier 是柠檬甜
 * @date 2020-12-17 15:35
 * @Version V1.0
 */
@WebServlet("/commentShowInList.do")
public class CommentShowInListServlet extends BaseServletPost {
    private CommentService commentService=new CommentServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        User user = (User) req.getSession().getAttribute("user");
        try{
            List<CommentVo> list = commentService.showComment(user.getUserName(), null,null);
            for (CommentVo commentVo:list) {
                commentVo.setCommentTimeStr(commentVo.getCommentTime());
            }
            System.out.println(list);
            successResultWrite(list,resp);
        }catch (RuntimeException e){
            String message = e.getMessage();
            successResultWrite(message,resp);
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
